
var Flash = {
	MODALBOX_OPTS: {
		title: 'Netflux', width: 300, overlayOpacity: .35, transitions: false
	},

	ERROR_REGEX: /\[ERROR\]/,

	flash: function(s, opts) {
		var f = $('#flash');

		if (!s) {
			f.fadeOut(200);
			if (Flash.fadeOut) clearTimeout(Flash.fadeOut);
			return;
		}

		if (Flash.ERROR_REGEX.test(s)) {
			Flash.error(s, opts);
			return;
		}

		f.html(s.replace('<br />', ' ')).fadeIn(100);
		if (Flash.fadeOut) clearTimeout(Flash.fadeOut);
		Flash.fadeOut = setTimeout('Flash.flash()', 10000);
	},

	error: function(s, opts) {
		if (!s) {
			Modalbox.hide();
			return;
		}

		var mboxOpts = {};
		for (i in Flash.MODALBOX_OPTS) mboxOpts[i] = Flash.MODALBOX_OPTS[i];
		if (opts) for (i in opts) mboxOpts[i] = opts[i];

		Modalbox.show('<span>' + s.replace(Flash.ERROR_REGEX, '') + '</span>', mboxOpts);
	}
};

